package example.file;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

import java.io.FileOutputStream;

public class PdfPasswordRemoval {

    public static void main(String[] args) {
        String inputPdf = "D:\\ROOT\\桌面1\\浦发银行\\20210816000045036618.pdf"; // 输入PDF文件路径
        String outputPdf = "D:\\ROOT\\桌面1\\浦发银行\\222.pdf"; // 输出PDF文件路径
        String password = "07561X"; // PDF文件的密码

        try {
            PdfReader pdfReader = new PdfReader(inputPdf, password.getBytes());
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(outputPdf));
            pdfStamper.close();
            pdfReader.close();

            System.out.println("密码已成功删除并保存到" + outputPdf);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
